package com.clouddot.baipai.model;


import android.content.Context;

import com.clouddot.baipai.contract.IPersonFragmentContract;
import com.clouddot.baipai.http.BanPaiRetrofitHelper;
import com.clouddot.baipai.http.PushLeaveNoRetrofitHelper;
import com.clouddot.baipai.http.entity.response.applyLeaveResponse;
import com.clouddot.baipai.http.entity.response.getLeaveRecordResponse;
import com.clouddot.baipai.http.entity.response.getLeaveTypeResponse;
import com.clouddot.baipai.http.entity.response.getPersonInfoResponse;
import com.clouddot.baipai.infrastructure.environment.Env;
import com.google.gson.Gson;

import org.wxy.sdk.base.impl.BaseModelImpl;

import java.util.HashMap;
import java.util.Map;

import okhttp3.RequestBody;
import rx.Observable;

public class PersonFragmentModel extends BaseModelImpl implements IPersonFragmentContract.IModel {
    public PersonFragmentModel(Context context) {
        super(context);

    }




    @Override
    public Observable<getPersonInfoResponse> getPersonInfo(String acttype) {
        return BanPaiRetrofitHelper.getInstance(Env.getContent()).getServer().getPersonInfo(Env.getAppContext().IP,acttype);

    }

    @Override
    public Observable<applyLeaveResponse> applyLeave(String acttype, String LeaveType, String LeaveTypeText, String LeaveStart, String LeaveEnd, String LeaveReason) {
        return BanPaiRetrofitHelper.getInstance(Env.getContent()).getServer().applyLeave(Env.getAppContext().IP,acttype,LeaveType,LeaveTypeText,LeaveEnd,LeaveEnd,LeaveReason);

    }

    @Override
    public Observable<getLeaveTypeResponse> getLeaveType(String acttype, String id) {
        return BanPaiRetrofitHelper.getInstance(Env.getContent()).getServer().getLeaveType(Env.getAppContext().IP,acttype,id);

    }

    @Override
    public Observable<getLeaveRecordResponse> getLeaveRecord(String acttype, int pageindex, int pagesize) {
        return BanPaiRetrofitHelper.getInstance(Env.getContent()).getServer().getLeaveRecord(Env.getAppContext().IP,acttype,pageindex,pagesize);

    }

    @Override
    public Observable<String> pushLeaveNo(String cardID, String LeaveTypeText, String LeaveStart, String LeaveEnd, String LeaveReason) {
        Map<String, Object> params = new HashMap<>();
        params.put("sn",cardID);
        params.put("type",LeaveTypeText);
        params.put("reason",LeaveReason);
        params.put("time_start",LeaveStart);
        params.put("time_stop",LeaveEnd);
        String json= new Gson().toJson(params);//要传递的json
        RequestBody requestBody=RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),json);
        return PushLeaveNoRetrofitHelper.getInstance(Env.getContent()).getServer().pushLeaveNo(requestBody);
    }


}
